<template>
  <div>
    <div class="search">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="举报人">
          <el-input v-model="formInline.user" placeholder="举报人" clearable />
        </el-form-item>
        <el-form-item label="举报对象">
          <el-input v-model="formInline.user2" placeholder="举报对象" clearable />
        </el-form-item>
        <el-form-item label="举报时间">
          <el-date-picker
            v-model="value1"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            clearable
          />
        </el-form-item>
        <el-form-item label="受理时间">
          <el-date-picker
            v-model="value2"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table
        :data="tableData"
        style="width: 100%"
        :fit="true"
      >
        <el-table-column
          label="处理状态"
          width="100"
          align="center"
        >
          <template slot-scope="scope">
            <el-tag :type="scope.row.type === 0 ? 'warning': 'success'" effect="dark">{{ scope.row.type === 0 ? '未受理' : '已处理' }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="举报时间"
          width="200"
          align="center"
        >
          <template slot-scope="scope">
            <i class="el-icon-time" />
            <span style="margin-left: 10px">{{ scope.row.createTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="受理时间"
          width="200"
          align="center"
        >
          <template slot-scope="scope">
            <i class="el-icon-time" />
            <span style="margin-left: 10px">{{ scope.row.processingTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="举报人"
          width="180px"
          align="center"
        >
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium" effect="dark" type="success">{{ scope.row.username }}</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="举报对象"
          width="180"
          align="center"
        >
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium" effect="dark" type="success">{{ scope.row.username1 }}</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="举报回答"
          width="480"
          align="center"
        >
          <template slot-scope="scope">
            <div slot="reference" style="height:100px" class="name-wrapper">
              <span v-html="scope.row.content" />
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="举报类型"
          width="100"
          align="center"
        >
          <template>
            <el-tag effect="dark">举报回答</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handlePass(scope.row)"
            >查看</el-button>
            <el-dropdown style="margin-left: 10px">
              <el-button type="danger" size="mini">
                操作<i class="el-icon-arrow-down el-icon--right" />
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="delArticle(scope.row)">删除文章</el-dropdown-item>
                <el-dropdown-item @click.native="ignore(scope.row)">觉得正常</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="paging">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="total"
        :current-page="currentPage"
      />
    </div>
  </div>
</template>

<script>
import { getQuestionAnswerReportList, treatment } from '@/api/report'
import { delArticle } from '@/api/article'
export default {
  data() {
    return {
      small: 'mini',
      formInline: {
        user: '',
        user2: '',
        region: ''
      },
      value1: [],
      value2: [],
      tableData: [],
      total: 1,
      currentPage: 1
    }
  },
  mounted() {
    this.getQuestionAnswerReportList()
  },
  methods: {
    getQuestionAnswerReportList() {
      var startTime1
      var endTime1
      if (this.value1 === null) {
        startTime1 = null
        endTime1 = null
      } else {
        startTime1 = typeof this.value1[0] === 'undefined' ? null : this.value1[0]
        endTime1 = typeof this.value1[1] === 'undefined' ? null : this.value1[1]
      }
      var startTime2
      var endTime2
      if (this.value2 === null) {
        startTime2 = null
        endTime2 = null
      } else {
        startTime2 = typeof this.value2[0] === 'undefined' ? null : this.value2[0]
        endTime2 = typeof this.value2[1] === 'undefined' ? null : this.value2[1]
      }
      getQuestionAnswerReportList({ username: this.formInline.user, _username: this.formInline.user2,
        startTime1: startTime1, endTime1: endTime1, startTime2: startTime2, endTime2: endTime2,
        pageIndex: this.currentPage }).then(res => {
        this.tableData = res.data.list
        this.total = res.data.total
        this.currentPage = res.data.pageNum
      })
    },
    onSubmit() {
      this.getQuestionAnswerReportList()
    },
    handlePass(report) {
      // changeStatus({ applicationId: application.id, num: 1 }).then(res => {
      //   this.getUnAuditList()
      // })
      window.open('/#/question/' + report.qid)
    },
    handleReject(application) {
      // changeStatus({ applicationId: application.id, num: 2 }).then(res => {
      //   this.getUnAuditList()
      // })
    },
    delArticle(row) {
      delArticle({ articleId: row.itemId }).then(res => {
        row.type = 1
        treatment({ id: row.id }).then(res => {
          this.getQuestionAnswerReportList()
        })
      })
    },
    ignore(row) {
      treatment({ id: row.id }).then(res => {
        this.getQuestionAnswerReportList()
      })
    }
  }
}
</script>

<style scoped lang="scss">
.search{
  padding-top: 20px;
  padding-left: 20px;
}
.paging {
  margin-top: 30px;
  text-align: center;
}
  .el-dropdown {
    vertical-align: top;
  }
  .el-dropdown + .el-dropdown {
    margin-left: 15px;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
</style>
